package com.itheima.info.manage.system.service;

import com.itheima.info.manage.system.dao.TeacherDao;
import com.itheima.info.manage.system.domain.Teacher;

import java.util.ArrayList;

public class TeacherService {
    //封装一个 操作数据对象
    private TeacherDao dao = new TeacherDao();

    //增
    public void addTeacher(Teacher teacher) {
        dao.addTeacher(teacher);
    }

    //删
    public void deleteTeacherBySid(String sid) {
        dao.deleteTeacherBySid(sid);
    }

    //改
    public void updateTeacher(String sid, Teacher newTeacher) {
        dao.updateTeacher(sid, newTeacher);
    }

    //查

    public ArrayList<Teacher> findAllTeachers() {
        return dao.findAllTeachers();

    }

    //判断指定的工号是否 存在
    public boolean isExist(String sid){
        ArrayList<Teacher> list = dao.findAllTeachers();
        for (int i = 0; i < list.size(); i++) {
            Teacher teacher = list.get(i);
            if(teacher.getSid().equals(sid)){
                return true;
            }
        }
        return false;


    }
}
